<!-- home -->
<template>
  <div class="index-container">
    <div class="top-search-body">
      <van-field class="input-value" @keyup.enter.native="searchWord" v-model="keywords"  placeholder="请输入关键字" />
      <img src="../../../static/search.png" class="search-img" alt="">
    </div>
<!--    <div class="list-title">-->
<!--      <div class="list-title-left">我的维修</div>-->
<!--      <div class="list-title-right" >查看全部 ></div>-->
<!--    </div>-->
    <div class="listBar">
      <div :class="type === 1 ? 'baritem choosebar' : 'baritem'" @click="changeBar(1)">
        维修中
        <div></div>
      </div>
      <div :class="type === 2 ? 'baritem choosebar' : 'baritem'"  @click="changeBar(2)">
        已完成
        <div></div>
      </div>
    </div>
    <div class="list">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <list-item v-for="(item, index) in data"  :data="item" :key="index"></list-item>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import ListItem from './listItem';
import { getList } from '@/api/home.js'
export default {
  components: { ListItem },
  data() {
    return {
      finished: false,
      refreshing: false,
      loading: false,
      keywords: '',
      page: 1,
      rows_count: 10,
      data: [],
      type: 1
    }
  },

  computed: {},

  mounted() {
    this.list()
  },

  methods: {
    changeBar(e) {
      this.type = e
      this.page = 1
      this.list()
    },
    searchWord() {
      this.page = 1
      this.list()
    },
    onLoad() {
      this.list()
    },
    onRefresh() {
      this.page = 1
      this.refreshing = false
      this.list()
    },
    list() {
      this.loading = true
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
      });
      let params = {
        keywords: this.keywords,
        page: this.page,
        rows_count: this.rows_count,
        type: this.type
      }
      getList(params).then((res) => {
        this.$toast.clear()
        // if (res.)
        this.loading = false
        this.page++
        this.data = res.data.data
        // this.data = [...this.data, ...res.data.data]
        if (res.data.data.length < this.rows_count) {
          this.finished = true
        }
      }).catch((e) => { console.log(e) })
    }
  }
}
</script>
<style lang="scss" scoped>
.index-container{
  padding: 0 15px;
}
.top-search-body{
  width: 100%;
  height: 44px;
  background: #FFFFFF;
  box-shadow: 0px 1px 4px 0px rgba(160, 160, 160, 0.35);
  border-radius: 22px;
  margin: 0 auto;
  margin-top: 23px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-value{
  padding: 0;
  margin-left: 22.5px;
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: 400;
  color:#333;
  width:200px;
}
.search-img{
  width:22px;
  height:22px;
  margin-right: 22px;
}
.list-title{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}
.list-title-left{
  border-left: 2px solid #a82025;
  padding-left: 12.5px;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #191919;
  height: 18px;
  line-height: 18px;
}
.list-title-right{
  font-size: 15px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #191919;
}
.list{
  margin-top: 14px;
}
.list-item{
  margin-bottom: 10px;
  width: 345px;
  background: #FFFFFF;
  box-shadow: 0px 1px 3px 0px rgba(43, 31, 56, 0.2);
  border-radius: 5px;
}
.listBar{
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  margin-top: 27px;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #C2C2C2;
}
.choosebar{
  font-weight: 500;
  color: #A82025;
}
.choosebar div{
  width: 15px;
  height: 2px;
  background: #A82025;
  border-radius: 1px;
  margin: 0 auto;
  margin-top: 7.5px;
}
</style>
<style lang="scss">
html,body{
  width:100%;
  height:100%;
  background-color: #f4f4f4 ;
}
.top-search-body .van-cell::after{
  display: none;
}
</style>
